package game.games.hexagon;

import game.AbstractGame;
import game.AbstractRunnable;
import game.Position;

import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class Hexagon extends AbstractRunnable
{
    private static Hexagon instance;
    
    public synchronized static Hexagon getInstance()
    {
        if (instance == null)
        {
            synchronized (Hexagon.class)
            {
                instance = new Hexagon();
                // for (IConsoleCommand commandObj :
                // HexagonCommands.getCommands())
                // {
                // Console.getInstance().addConsoleCommand(commandObj);
                // }
            }
        }
        return instance;
    }

    private Position frameSize;
    
    @Override
    public void render(Graphics g)
    {
        if (frameSize != null)
        {
            int corners = 8;
            int x = 25;
            int width = 15;
            Polygon p = new Polygon();
            for (int i = 0; i < corners; i++)
            {
                p.addPoint((int) (x + width * Math.cos(i * 2 * Math.PI / corners)), (int) (x + width * Math.sin(i * 2 * Math.PI / corners)));
            }
            g.drawPolygon(p);
            
            Polygon s = new Polygon();
            for (int i = 0; i < 360; i++)
            {
                double t = i / 360.0;
                s.addPoint((int) (150 + 50 * t * Math.cos(8 * t * Math.PI)), (int) (150 + 50 * t * Math.sin(8 * t * Math.PI)));
            }
            g.drawPolygon(s);
        }
    }

    @Override
    protected void doNext()
    {
    }
    
    @Override
    protected synchronized void reset()
    {
        frameSize = new Position(HexagonRunner.getInstance().getSize());
        super.reset();
    }
    
    @Override
    public MouseListener getMouseControl()
    {
        return new MouseAdapter() {};
    }
    
    @Override
    public MouseMotionListener getMouseMotionListener()
    { 
        return null;
    }
    
    public static class HexagonRunner extends AbstractGame
    {
        private static HexagonRunner instance;
        
        public synchronized static HexagonRunner getInstance()
        {
            synchronized (HexagonRunner.class)
            {
                if (instance == null)
                {
                    instance = new HexagonRunner();
                }
                return instance;
            }
        }
        
        protected HexagonRunner()
        {
            super(Hexagon.getInstance());
        }
        
        public static void main(String[] args)
        {
            Thread t = new Thread(HexagonRunner.getInstance(), "Hexagon");
            t.start();
        }
    }
}
